package nl.sportan.samenloop.communication;

import java.util.ArrayList;

import nl.sportan.samenloop.model.Message;

public class StreamingRSSReader implements Runnable {

	private FeedParser parser;
	private Result<ArrayList<Message>> resultHandler = null;

	public StreamingRSSReader(String url) {
		parser = new XmlPullFeedParser(url);
	}

	public void setResultHandler(Result<ArrayList<Message>> resultHandler) {
		this.resultHandler = resultHandler;
	}

	public void run() {
		ArrayList<Message> messages = null;

		try {
			messages = parser.parse();
		} catch (RuntimeException re) {
			resultHandler.onFailure(re);
		}
		if (resultHandler != null) {
			resultHandler.onSucces(messages);
		}
	}

}
